package cn.iocoder.yudao.module.member.service.userfacelogs;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.member.controller.admin.userfacelogs.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.userfacelogs.UserFaceLogsDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.member.dal.mysql.userfacelogs.UserFaceLogsMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;

/**
 * 用户面试日志 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserFaceLogsServiceImpl implements UserFaceLogsService {

    @Resource
    private UserFaceLogsMapper userFaceLogsMapper;

    @Override
    public Long createUserFaceLogs(UserFaceLogsSaveReqVO createReqVO) {
        // 插入
        UserFaceLogsDO userFaceLogs = BeanUtils.toBean(createReqVO, UserFaceLogsDO.class);
        userFaceLogsMapper.insert(userFaceLogs);
        // 返回
        return userFaceLogs.getId();
    }

    @Override
    public void updateUserFaceLogs(UserFaceLogsSaveReqVO updateReqVO) {
        // 校验存在
        validateUserFaceLogsExists(updateReqVO.getId());
        // 更新
        UserFaceLogsDO updateObj = BeanUtils.toBean(updateReqVO, UserFaceLogsDO.class);
        userFaceLogsMapper.updateById(updateObj);
    }

    @Override
    public void deleteUserFaceLogs(Long id) {
        // 校验存在
        validateUserFaceLogsExists(id);
        // 删除
        userFaceLogsMapper.deleteById(id);
    }

    private void validateUserFaceLogsExists(Long id) {
        if (userFaceLogsMapper.selectById(id) == null) {
            throw exception(USER_FACE_LOGS_NOT_EXISTS);
        }
    }

    @Override
    public UserFaceLogsDO getUserFaceLogs(Long id) {
        return userFaceLogsMapper.selectById(id);
    }

    @Override
    public PageResult<UserFaceLogsDO> getUserFaceLogsPage(UserFaceLogsPageReqVO pageReqVO) {
        return userFaceLogsMapper.selectPage(pageReqVO);
    }

}